Ext.define('AM.view.ShenpiWorkView', {
		extend: 'Ext.grid.Panel',
		alias : 'widget.shenpiWorkView',
		store : 'ShenpiWorkStore',
		columnLines:true,
//		selModel : Ext.create('Ext.selection.CheckboxModel'),
		selModel: {
	        injectCheckbox: 0,
	        mode: "SIMPLE"     //"SINGLE"/"SIMPLE"/"MULTI"
	       
   		 },
   		selType: "checkboxmodel",
    	dockedItems: [{
        xtype: 'pagingtoolbar',
        dock: 'bottom',
        store : 'ShenpiWorkStore',
        displayInfo: true
    }],
     plugins: [{
            ptype: 'rowexpander',
            rowBodyTpl : new Ext.XTemplate(
                 '<p><b>项目名称:</b> {name}</p>',
                '<p><b>工作内容:</b> {content}</p>'
            )
     }],
		columns: [	
			        {text: '序号', xtype: 'rownumberer',width:50,align:'center'},
			        { text: '项目名称', dataIndex: 'name', width:100,align:'center'},
			        { text: '科室', dataIndex: 'department', width:100,align:'center'},
			        { text: '申请人', dataIndex: 'employee', width:100,align:'center'},
			        { text: '开始时间', dataIndex: 'starttime', width:140,align:'center',xtype: 'datecolumn',format:'Y-m-d'},
			        { text: '结束时间', dataIndex: 'endtime', width:140,align:'center',xtype: 'datecolumn',format:'Y-m-d'},
			        { text: '工作内容', dataIndex: 'content', width:120,align:'center'},
			        { text: '审批意见', dataIndex: 'advice', width:120,align:'center'},
			        { text: '状态', dataIndex: 'state', width:120,align:'center',renderer: function(value){
					        	 if (value === 0) {
										 	return '<span>待审批</span>';
								 }if (value === 1) {
										return '<span style="color:green;">审批通过</span>';
								 }if (value === 2) {
										return '<span style="color:red;">审批未通过</span>';
								 }
								 }
			        },
			        { text: '操作', dataIndex: 'id', width:120,align:'center',renderer : function(data, cell, record, rowIndex,columnIndex){
			        	    var resultStr = "<div class='controlBtn'>" +     
                            "<a href='javascript:void("+record.get('id')+");'class='alarm_detail'onclick='ShenpiWork("+record.get('id')+")'>审批</a> &nbsp;&nbsp;&nbsp;&nbsp;"+ 
                             "<a href='javascript:void("+record.get('id')+");'class='alarm_detail'onclick='Quxiaoshenpi("+record.get('id')+")'>取消审批</a>"
                            "</div>";     
         					 return resultStr;  
			       		  }}
			     ]
//			   tbar: [
//					  { xtype: 'button', text: '增加',icon: 'Ext/restful/images/add.png'
//					  }
//					  { xtype: 'button', text: '修改',icon: 'Ext/restful/images/cog_edit.png'
//					  },
//					  { xtype: 'button', text: '删除',icon: 'Ext/restful/images/delete.png'
//					  }
//					]	
})
function Quxiaoshenpi(id){
	 Ext.Ajax.request({
					url : 'AddWork_Quxiaoshenpi',
					success : function() {
							Ext.MessageBox.alert("提示", "取消审批成功！");
							View=Ext.create('AM.view.ShenpiWorkView')
						    View.getStore().reload();
						},
					failure : function() {
							Ext.MessageBox.alert("提示", "待审批！");
					 },
					 params : {
							id:id	
							}
				});		
}
 function ShenpiWork(id){
 	   Ext.Ajax.request({
					url : 'AddWork_JianChaWork',
					success : function() {
							 var myform1= new Ext.form.Panel({
										       bodyPadding: 15,
										        items: [{
										        		 xtype : "combobox",
														 allowBlank:false,
														 width:300,
													     emptyText:'是否同意',
														 selectOnFocus:true,
														 forceSelection: true,
														 queryMode: 'local',
														 labelAlign :"right",
														 fieldLabel: '审批意见',
														 name: 'state',
														 store :Ext.create('Ext.data.Store', {
																 fields: ['id', 'name'],
																 data : [
																 		{"id":"1", "name":"同意"},
																        {"id":"2", "name":"不同意"}  
																    ]
																}),
														 displayField: 'name',
														 valueField: 'id',
														  listeners:{   
														  			select:function(combo,record,index){
														  				if(this.value==2){
														  					
														  					 Ext.getCmp('tastproperty_123').setDisabled(true);
														  					 Ext.getCmp('fen_123').setDisabled(true);
														  				}if(this.value==1){
														  					Ext.getCmp('tastproperty_123').setDisabled(false);
														  					 Ext.getCmp('fen_123').setDisabled(false);
														  				}
														  			}
														  }
														 
										           },{
												 		 fieldLabel: '等级',
														 emptyText:'请选等级',
														 xtype:"combobox",
													     labelAlign :"right",
													     selectOnFocus:true,
														 queryMode: 'local',
														 name: 'tastproperty',
														 width:300,
														 id:'tastproperty_123',
														 forceSelection: true,  
														 store :Ext.create('Ext.data.Store', {
																	    fields: ['id','name'],
																	    data : [
																			      {"id":1, "name":"一级"},
																			      {"id":2, "name":"二级"},
																			      {"id":3, "name":"三级"},
																	              {"id":4, "name":"四级"}
																	        ]
															 		}),
														 displayField: 'name',
						    							 valueField: 'id',
						    							 listeners:{   
																	select:function(combo,record,index){
																		 try{
																				 var parent=Ext.getCmp('fen_123');
																				 parent.clearValue();
																				 parent.store.load({params:{param:this.value}});
																			 }
																		 catch(ex){
																					 Ext.MessageBox.alert("错误","数据加载失败。");
																				 }
																		}
																}
								          	        	
										           },{
														 emptyText:'请选择得分',
														 fieldLabel: '项目分数',
														 id:'fen_123',
														 xtype:"combobox",
													     labelAlign :"right",
													     width:300,
													     forceSelection: true,  
													     selectOnFocus:true,
														 queryMode: 'local',
														 name: 'core',
														 store :"CoreStore",
														 displayField: 'core',
						    							 valueField: 'core'
										           },{		      
														 xtype : "textarea",
														 fieldLabel: '审批意见',
														 labelAlign :"right",
														 width:500,
														 name: 'advice',
														 grow : true
										        	 }]
							 	 })
									var win = new Ext.Window({
											title : "审批临时性工作",
											width : 650,
											height : 350,
											frame:true,
											layout:'fit',
										    items :[myform1],
											buttons : [
													  {text : "确定",
															handler : function() {
																win.getComponent(0).getForm().submit({
																			    url : 'AddWork_ShenpiWork',
																			    success : function() {
																				Ext.Msg.alert('提示', '审批成功');
																				win.close();
																				WorkView=Ext.create('AM.view.ShenpiWorkView');
																				WorkView.getStore().reload();
																				
																			},
																			failure : function() {
																				Ext.Msg.alert('错误', '审批失败');
																			},
																			waitMsg : "请稍后，正在保存。。。。",
																		params : {
																						id:id	
																					}
																	});
															}
														}, {
															text : "重置",
															handler : function() {
																win.getComponent(0).getForm().reset();
															}
														}, {
															text : "取消",
															handler : function() {
																				win.close();
																			
															}
												}]
							 	}).show();
		
						},
					failure : function() {
							Ext.MessageBox.alert("提示", "已经审批！");
					 },
					 params : {
							id:id	
							}
				});		
		
   
 }
